#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
// a + k = t1 * p
// b + k = t2 * p
// a - b = (t1 - t2) * p
// p <= a - b
// p == a - b
int main()
{
    LL a, b;
    cin >> a >> b;
    LL d = abs(a - b);
    cout << (d == 0 ? 0 : d - a % d) << endl;
    return 0;
}